<%@ include file="header.jsp" %>
<%
	if (request.getAttribute("password") != null) {
		String newPass = ((String)request.getAttribute("password")).trim();
		
		//Change the session variable for password if it was updated.
		if (newPass != null) {		
			if(!newPass.equals((String)session.getAttribute("password"))) {
				session.setAttribute("password", newPass.trim());
			}		
		}		
	}
%>

<h1>Admin Page</h1>

<c:if test="${ sessionScope.userClass == 'a' }">

<div>
	<h2>Add New User</h2>
	<fieldset>
	${messages.new_user_msg}
		<form class="user_info" id="add_user_form" name="add_user" method="post" action="AddUser">
			<label for="username">Username:</label>
			<input class="required" name="username" type="text" value=""> 
	
			<label for="password" >Password:</label>
			<input class="required" name="password" type="password" value=""> 
			
			<label for="userclass">Class</label>
				<select name="userclass">
					<option value="p">Person</option>
					<option value="d">Doctor</option>
					<option value="r">Radiologist</option>
					<option value="a">Administrator</option>
				</select>
			
			<label for="first_name">First Name:</label>
			<input name="first_name" type="text" value=""> 
	
			<label for="last_name">Last Name:</label>
			<input name="last_name" type="text" value=""> 		
			
			<label for="address">Address:</label>
			<input name="address" type="textarea" value=""> 		
	
			<label for="email">Email:</label>
			<input class="required email" name="email" type="text" value=""> 		
	
			<label for="phone">Phone (10 digits):</label>
			<input name="phone" type="text" value=""> 				
	
			<input type="submit" value="submit">
		</form>	
	</fieldset>
</div>
<div>
	<h2>Users</h2>
	${messages.delete_user_msg}
	${messages.update_msg}
	
	<table>
	<tr>
		<th>Username</th>
		<th>First Name</th>
		<th>Last Name</th>
		<th>Address</th>
		<th>Email</th>	
		<th>Phone</th>
		<th>Actions</th>	
		
	</tr>				
	
	<c:forEach var="user" items="${users}">
		<tr>
			<td>${user.userName}</td>
			<td>${user.firstName}</td>
			<td>${user.lastName}</td>
			<td>${user.address}</td>
			<td>${user.email}</td>
			<td>${user.phone}</td>
			<td><a class="edit_link" id="${user.userName}" href="EditForm?user_name=${user.userName}">Edit</a> 
				<c:if test="${user.userName != sessionScope.username }" >
				| <a class="delete_link" href="DeleteUser?id=${user.userName }" id="${user.userName}">Delete</a>
				</c:if>
		</tr>
	</c:forEach>
	</table>	

</div>
</c:if>
<%@ include file="footer.jsp" %>